#ifndef __DIGITAL_IO_H__
#define __DIGITAL_IO_H__

#include "wiring_constants.h"
#include "PinNames.h"

#ifdef __cplusplus
extern "C"
{
#endif

    /**
  * @brief  This function set a value to an IO
  * @param  pn : Pin name
  * @param  val : 0 to set to low, any other value to set to high
  * @retval None
  */
    static inline void digitalWriteFast(PinName pn, uint32_t ulVal)
    {
        GPIO_WriteBit(REF_GPIO_PORT(pn), REF_GPIO_PIN(pn), ulVal == LOW ? Bit_RESET : Bit_SET);
    }
    /**
  * @brief  This function read the value of an IO
  * @param  pn : Pin name
  * @retval The pin state (LOW or HIGH)
  */
    static inline int digitalReadFast(PinName pn)
    {
        return (GPIO_ReadInputDataBit(REF_GPIO_PORT(pn), REF_GPIO_PIN(pn)));
    }

    /**
  * @brief  This function toggle value of an IO
  * @param  port : one of the gpio port
  * @param  pin : one of the gpio pin
  * @retval None
  */
    static inline void digitalToggleFast(PinName pn)
    {
        GPIO_TypeDef*GPIOx = REF_GPIO_PORT(pn);
        uint32_t GPIO_Pin = REF_GPIO_PIN(pn);
	      GPIOx->OUTDR ^= GPIO_Pin;
    }
#ifdef __cplusplus
}
#endif

#endif // __DIGITAL_IO_H__